package com.yic.module.base.api.unit;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.yic.module.base.api.unit.dto.UnitRespDTO;
import com.yic.module.base.convert.unit.UnitConvert;
import com.yic.module.base.dal.dataobject.unit.UnitDO;
import com.yic.module.base.service.unit.UnitService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * @ClassName UnitApiImpl
 * @Description 单位API实现
 * @Author Lijx
 * @Date 2023/11/6 17:19
 * @Version 1.0
 */
@Service
public class UnitApiImpl implements UnitApi {

    @Resource
    private UnitService unitService;

    @Override
    public UnitRespDTO getUnit(Long id) {
        if (ObjectUtil.isNull(id)){
            return null;
        }
        UnitDO unit = unitService.getUnit(id);
        return UnitConvert.INSTANCE.convert01(unit);
    }

    @Override
    public List<UnitRespDTO> getUnitList() {
        List<UnitDO> unitList = unitService.getUnitList();
        return UnitConvert.INSTANCE.convertList04(unitList);
    }

    @Override
    public UnitRespDTO getUnitByErpId(String erpUnitId) {
        if (ObjectUtil.isNull(erpUnitId)){
            return null;
        }
        UnitDO unit = unitService.getUnitByErpId(erpUnitId);
        return UnitConvert.INSTANCE.convert01(unit);
    }

    @Override
    public List<UnitRespDTO> getUnitListByErpId(Collection<String> erpUnitIds) {
        if (CollectionUtil.isEmpty(erpUnitIds)) {
            return Collections.emptyList();
        }
        List<UnitDO> unitList = unitService.getUnitListByErpId(erpUnitIds);
        return UnitConvert.INSTANCE.convertList04(unitList);
    }
}
